<?php

class NewsItem extends DataObject {

    static $db = array(
        'Title' => 'Varchar(255)',
        'Date' => 'Date',
        'Message' => 'HTMLText',
        'Archive' => 'Boolean',
    );
    static $searchable_fields = array(
        'Title',
        'Date',
        'Message',
    );
    static $has_one = array(
        'Image' => 'Image',
        'NewsPage' => 'NewsPage',
    );

    public function getCMSFields_forPopup() {
        //$df = new DateField('Date');
        //$df->setConfig('showcalendar', true);
        //$df->setConfig('dateformat', 'dd/MM/YYYY');
        $df = new DatePickerField('Date');
        //$df->setConfig('dateformat', 'YYYY-MM-dd');
        //$df->setConfig('showcalendar', true);
        return new FieldSet(
                new TextField('Title'),
                $df,
                new CheckboxField('Archive'),
                new ImageField('Image'),
                new SimpleHtmlEditorField('Message') // SimpleHTMLEditorField
        );
    }

    public function getCMSFields() {
        $df = new DatePickerField('Date', 'Publicatiedatum');
//        $df->setConfig('showcalendar', true);
//        $df->setConfig('dateformat', 'YYYY-MM-dd');
//        $df = new TextField('NewsDate', 'Publicatiedatum');
        return new FieldSet(
                new TextField('Title', 'Titel'),
                $df,
                new CheckboxField('Archive', 'Gearchiveerd'),
                new ImageField('Image', 'Afbeelding'),
                new HtmlEditorField('Message', 'Nieuwsbericht') // SimpleHTMLEditorField
        );
    }
    
    public function onBeforeWrite() {
        parent::onBeforeWrite();
        $newsPage = DataObject::get_one('NewsPage');
        $this->NewsPageID = $newsPage->ID;
    }

}